using System;
using System.Data;
using System.IO;
using Oracle.ManagedDataAccess.Client;
using OracleInternal.Common;
using OracleInternal.ServiceObjects;

namespace Oracle.ManagedDataAccess.Types
{
	public sealed class OracleBFile : Stream, ICloneable, INullable, IDisposable
	{
		internal OracleBFileImpl m_bfileImpl;

		internal OracleConnection m_connection;

		internal bool m_isTemporaryLob;

		private OracleCommand m_command;

		private string m_directoryName;

		private bool m_fileExists;

		private string m_fileName;

		private long m_length;

		private long m_position;

		internal bool m_isEmpty;

		private bool m_isFileOpen;

		private bool m_bNotNull = true;

		private bool m_bClosed;

		private bool m_bDisposed;

		private object lockBFile = new object();

		public const long MaxSize = 4294967295L;

		public new static readonly OracleBFile Null = new OracleBFile();

		public override bool CanRead
		{
			get
			{
				if (!m_bNotNull)
				{
					return true;
				}
				if (m_bClosed)
				{
					return false;
				}
				return true;
			}
		}

		public override bool CanSeek
		{
			get
			{
				if (!m_bNotNull)
				{
					return true;
				}
				if (m_bClosed)
				{
					return false;
				}
				return true;
			}
		}

		public override bool CanWrite => false;

		public override long Length
		{
			get
			{
				if (!m_bNotNull)
				{
					return 0L;
				}
				if (m_bClosed || !m_isFileOpen)
				{
					throw new InvalidOperationException(OracleStringResourceManager.GetErrorMesg(ResourceStringConstants.OBJECT_CLOSED));
				}
				m_length = m_bfileImpl.GetLength();
				return m_length;
			}
		}

		public byte[] Value
		{
			get
			{
				if (!m_bNotNull)
				{
					throw new OracleNullValueException();
				}
				if (m_bClosed || !m_isFileOpen)
				{
					throw new InvalidOperationException(OracleStringResourceManager.GetErrorMesg(ResourceStringConstants.OBJECT_CLOSED));
				}
				long position = m_position;
				m_position = 0L;
				int num = 0;
				long length = Length;
				num = (int)((length < int.MaxValue) ? length : int.MaxValue);
				byte[] array = new byte[num];
				Read(array, 0, num);
				m_position = position;
				return array;
			}
		}

		public override long Position
		{
			get
			{
				if (!m_bNotNull)
				{
					return 0L;
				}
				if (m_bClosed || !m_isFileOpen)
				{
					throw new InvalidOperationException(OracleStringResourceManager.GetErrorMesg(ResourceStringConstants.OBJECT_CLOSED));
				}
				return m_position;
			}
			set
			{
				if (m_bNotNull)
				{
					if (m_bClosed || !m_isFileOpen)
					{
						throw new InvalidOperationException(OracleStringResourceManager.GetErrorMesg(ResourceStringConstants.OBJECT_CLOSED));
					}
					if (value < 0)
					{
						throw new ArgumentOutOfRangeException("Position");
					}
					m_position = value;
				}
			}
		}

		public bool IsNull => !m_bNotNull;

		public OracleConnection Connection
		{
			get
			{
				if (!m_bNotNull)
				{
					return null;
				}
				if (m_bClosed)
				{
					throw new InvalidOperationException(OracleStringResourceManager.GetErrorMesg(ResourceStringConstants.OBJECT_CLOSED));
				}
				return m_connection;
			}
		}

		public string DirectoryName
		{
			get
			{
				if (!m_bNotNull)
				{
					throw new OracleNullValueException();
				}
				if (m_bClosed)
				{
					throw new InvalidOperationException(OracleStringResourceManager.GetErrorMesg(ResourceStringConstants.OBJECT_CLOSED));
				}
				if (m_directoryName == null)
				{
					GetDFNames();
				}
				return m_directoryName;
			}
			set
			{
				if (!m_bNotNull)
				{
					throw new OracleNullValueException();
				}
				if (m_bClosed)
				{
					throw new InvalidOperationException(OracleStringResourceManager.GetErrorMesg(ResourceStringConstants.OBJECT_CLOSED));
				}
				if (IsOpen)
				{
					throw new InvalidOperationException(OracleStringResourceManager.GetErrorMesg(ResourceStringConstants.LOB_BFILE_ALREADY_OPEN));
				}
				m_directoryName = value;
			}
		}

		public bool FileExists
		{
			get
			{
				if (!m_bNotNull)
				{
					return false;
				}
				if (m_bClosed || !m_isFileOpen)
				{
					throw new InvalidOperationException(OracleStringResourceManager.GetErrorMesg(ResourceStringConstants.OBJECT_CLOSED));
				}
				m_fileExists = m_bfileImpl.FileExists();
				return m_fileExists;
			}
		}

		public string FileName
		{
			get
			{
				if (!m_bNotNull)
				{
					throw new OracleNullValueException();
				}
				if (m_bClosed)
				{
					throw new InvalidOperationException(OracleStringResourceManager.GetErrorMesg(ResourceStringConstants.OBJECT_CLOSED));
				}
				if (m_fileName == null)
				{
					GetDFNames();
				}
				return m_fileName;
			}
			set
			{
				if (!m_bNotNull)
				{
					throw new OracleNullValueException();
				}
				if (m_bClosed)
				{
					throw new InvalidOperationException(OracleStringResourceManager.GetErrorMesg(ResourceStringConstants.OBJECT_CLOSED));
				}
				if (IsOpen)
				{
					throw new InvalidOperationException(OracleStringResourceManager.GetErrorMesg(ResourceStringConstants.LOB_BFILE_ALREADY_OPEN));
				}
				m_fileName = value;
			}
		}

		public bool IsEmpty
		{
			get
			{
				if (!m_bNotNull)
				{
					throw new OracleNullValueException();
				}
				if (m_bClosed || !m_isFileOpen)
				{
					throw new InvalidOperationException(OracleStringResourceManager.GetErrorMesg(ResourceStringConstants.OBJECT_CLOSED));
				}
				if (Length != 0L)
				{
					return m_isEmpty = false;
				}
				return m_isEmpty = true;
			}
		}

		public bool IsOpen
		{
			get
			{
				if (!m_bNotNull)
				{
					return false;
				}
				if (m_bClosed)
				{
					throw new InvalidOperationException(OracleStringResourceManager.GetErrorMesg(ResourceStringConstants.OBJECT_CLOSED));
				}
				return m_isFileOpen;
			}
		}

		public OracleBFile(OracleConnection con)
			: this(con, string.Empty, string.Empty)
		{
		}

		public OracleBFile(OracleConnection connection, string directoryName, string fileName)
		{
			if (ProviderConfig.m_bTraceLevelPublic)
			{
				Trace.Write(OracleTraceLevel.Public, OracleTraceTag.Entry, OracleTraceClassName.OracleBFile, OracleTraceFuncName.ctor);
			}
			try
			{
				if (connection == null)
				{
					GC.SuppressFinalize(this);
					throw new ArgumentNullException("connection");
				}
				if (ConnectionState.Open != connection.m_connectionState)
				{
					throw new InvalidOperationException(OracleStringResourceManager.GetErrorMesg(ResourceStringConstants.CON_CLOSED));
				}
				m_connection = connection;
				m_directoryName = directoryName;
				m_fileName = fileName;
				m_bfileImpl = new OracleBFileImpl(connection.m_oracleConnectionImpl, null);
				m_isTemporaryLob = false;
				if (m_connection.m_oracleConnectionImpl != null)
				{
					m_connection.m_oracleConnectionImpl.RegisterForConnectionClose(this);
				}
			}
			catch (Exception ex)
			{
				OracleException.HandleError(OracleTraceLevel.Public, OracleTraceTag.Error, OracleTraceClassName.OracleBFile, OracleTraceFuncName.ctor, ex);
				throw;
			}
			finally
			{
				if (ProviderConfig.m_bTraceLevelPublic)
				{
					Trace.Write(OracleTraceLevel.Public, OracleTraceTag.Exit, OracleTraceClassName.OracleBFile, OracleTraceFuncName.ctor);
				}
			}
		}

		internal OracleBFile(OracleConnection connection, byte[] lobLocator)
		{
			if (ProviderConfig.m_bTraceLevelPrivate)
			{
				Trace.Write(OracleTraceLevel.Private, OracleTraceTag.Entry, OracleTraceClassName.OracleBFile, OracleTraceFuncName.ctor);
			}
			try
			{
				m_connection = connection;
				m_directoryName = null;
				m_fileName = null;
				m_bfileImpl = new OracleBFileImpl(connection.m_oracleConnectionImpl, lobLocator);
				if (m_connection.m_oracleConnectionImpl != null)
				{
					m_connection.m_oracleConnectionImpl.RegisterForConnectionClose(this);
				}
			}
			catch (Exception ex)
			{
				OracleException.HandleError(OracleTraceLevel.Private, OracleTraceTag.Error, OracleTraceClassName.OracleBFile, OracleTraceFuncName.ctor, ex);
				throw;
			}
			finally
			{
				if (ProviderConfig.m_bTraceLevelPrivate)
				{
					Trace.Write(OracleTraceLevel.Private, OracleTraceTag.Exit, OracleTraceClassName.OracleBFile, OracleTraceFuncName.ctor);
				}
			}
		}

		private OracleBFile()
		{
			m_bNotNull = false;
		}

		~OracleBFile()
		{
			if (ProviderConfig.m_bTraceLevelPublic)
			{
				Trace.Write(OracleTraceLevel.Public, OracleTraceTag.Entry, OracleTraceClassName.OracleBFile, OracleTraceFuncName.dtor);
			}
			try
			{
				try
				{
					Dispose(disposing: false);
				}
				catch (Exception ex)
				{
					OracleException.HandleError(OracleTraceLevel.Public, OracleTraceTag.Error, OracleTraceClassName.OracleBFile, OracleTraceFuncName.dtor, ex);
				}
			}
			finally
			{
				if (ProviderConfig.m_bTraceLevelPublic)
				{
					Trace.Write(OracleTraceLevel.Public, OracleTraceTag.Exit, OracleTraceClassName.OracleBFile, OracleTraceFuncName.dtor);
				}
			}
		}

		public override void Flush()
		{
		}

		public long Search(byte[] val, long offset, long nth)
		{
			if (ProviderConfig.m_bTraceLevelPublic)
			{
				Trace.Write(OracleTraceLevel.Public, OracleTraceTag.Entry, OracleTraceClassName.OracleBFile, OracleTraceFuncName.Search);
			}
			try
			{
				if (!m_bNotNull)
				{
					return 0L;
				}
				if (m_bClosed || !m_isFileOpen)
				{
					throw new InvalidOperationException(OracleStringResourceManager.GetErrorMesg(ResourceStringConstants.OBJECT_CLOSED));
				}
				if (val.Length > 16383)
				{
					throw new ArgumentOutOfRangeException("val");
				}
				if (offset < 0 || offset >= uint.MaxValue)
				{
					throw new ArgumentOutOfRangeException("offset");
				}
				if (nth <= 0 || nth >= uint.MaxValue)
				{
					throw new ArgumentOutOfRangeException("nth");
				}
				long num = 0L;
				offset++;
				if (m_command == null)
				{
					m_command = new OracleCommand();
				}
				m_command.Connection = m_connection;
				m_command.CommandText = "BEGIN :1 := DBMS_LOB.INSTR(:LOB_LOC, :PATTERN, :OFFSET, :NTH); END;";
				m_command.CommandType = CommandType.Text;
				try
				{
					OracleParameter oracleParameter = new OracleParameter("return_value", OracleDbType.Int64, num, ParameterDirection.ReturnValue);
					oracleParameter.DbType = DbType.Int64;
					m_command.Parameters.Add(oracleParameter);
					m_command.Parameters.Add("current_bfile", OracleDbType.BFile, this, ParameterDirection.Input);
					m_command.Parameters.Add("pattern", OracleDbType.Raw, val, ParameterDirection.Input);
					m_command.Parameters.Add("current_offset", OracleDbType.Int64, offset, ParameterDirection.Input);
					m_command.Parameters.Add("occurence", OracleDbType.Int64, nth, ParameterDirection.Input);
					m_command.ExecuteNonQuery();
					num = (long)m_command.Parameters[0].Value;
				}
				finally
				{
					m_command.Parameters.Clear();
				}
				return num;
			}
			catch (Exception ex)
			{
				OracleException.HandleError(OracleTraceLevel.Public, OracleTraceTag.Error, OracleTraceClassName.OracleBFile, OracleTraceFuncName.Search, ex);
				throw;
			}
			finally
			{
				if (ProviderConfig.m_bTraceLevelPublic)
				{
					Trace.Write(OracleTraceLevel.Public, OracleTraceTag.Exit, OracleTraceClassName.OracleBFile, OracleTraceFuncName.Search);
				}
			}
		}

		internal byte[] GetValue()
		{
			if (ProviderConfig.m_bTraceLevelPrivate)
			{
				Trace.Write(OracleTraceLevel.Private, OracleTraceTag.Entry, OracleTraceClassName.OracleBFile, OracleTraceFuncName.GetValue);
			}
			try
			{
				bool flag = false;
				if (!m_isFileOpen)
				{
					OpenFile();
					flag = true;
				}
				byte[] result = null;
				try
				{
					result = Value;
				}
				finally
				{
					if (flag)
					{
						CloseFile();
					}
				}
				return result;
			}
			catch (Exception ex)
			{
				OracleException.HandleError(OracleTraceLevel.Private, OracleTraceTag.Error, OracleTraceClassName.OracleBFile, OracleTraceFuncName.GetValue, ex);
				throw;
			}
			finally
			{
				if (ProviderConfig.m_bTraceLevelPrivate)
				{
					Trace.Write(OracleTraceLevel.Private, OracleTraceTag.Exit, OracleTraceClassName.OracleBFile, OracleTraceFuncName.GetValue);
				}
			}
		}

		internal byte[] GetLobLocator()
		{
			return m_bfileImpl.m_lobLocator;
		}

		internal void SetLobLocator(byte[] lobLocator, bool bTempLob)
		{
			m_bfileImpl.m_lobLocator = lobLocator;
			m_directoryName = null;
			m_fileName = null;
			m_isTemporaryLob = bTempLob;
		}

		public override long Seek(long offset, SeekOrigin origin)
		{
			if (ProviderConfig.m_bTraceLevelPublic)
			{
				Trace.Write(OracleTraceLevel.Public, OracleTraceTag.Entry, OracleTraceClassName.OracleBFile, OracleTraceFuncName.Seek);
			}
			try
			{
				if (!m_bNotNull)
				{
					return 0L;
				}
				if (m_bClosed || !m_isFileOpen)
				{
					throw new InvalidOperationException(OracleStringResourceManager.GetErrorMesg(ResourceStringConstants.OBJECT_CLOSED));
				}
				if (origin == SeekOrigin.Begin)
				{
					m_position = offset;
				}
				if (origin == SeekOrigin.Current)
				{
					m_position += offset;
				}
				if (origin == SeekOrigin.End)
				{
					m_position = Length + offset;
				}
				return m_position;
			}
			catch (Exception ex)
			{
				OracleException.HandleError(OracleTraceLevel.Public, OracleTraceTag.Error, OracleTraceClassName.OracleBFile, OracleTraceFuncName.Seek, ex);
				throw;
			}
			finally
			{
				if (ProviderConfig.m_bTraceLevelPublic)
				{
					Trace.Write(OracleTraceLevel.Public, OracleTraceTag.Exit, OracleTraceClassName.OracleBFile, OracleTraceFuncName.Seek);
				}
			}
		}

		public override void SetLength(long newLength)
		{
			throw new NotSupportedException();
		}

		public bool IsEqual(OracleBFile obj)
		{
			if (ProviderConfig.m_bTraceLevelPublic)
			{
				Trace.Write(OracleTraceLevel.Public, OracleTraceTag.Entry, OracleTraceClassName.OracleBFile, OracleTraceFuncName.IsEqual);
			}
			try
			{
				if (m_bClosed)
				{
					throw new InvalidOperationException(OracleStringResourceManager.GetErrorMesg(ResourceStringConstants.OBJECT_CLOSED));
				}
				if (m_bNotNull && !m_isFileOpen)
				{
					throw new InvalidOperationException(OracleStringResourceManager.GetErrorMesg(ResourceStringConstants.OBJECT_CLOSED));
				}
				if (obj == null)
				{
					throw new ArgumentNullException();
				}
				if (!m_bNotNull || obj.IsNull)
				{
					if (!m_bNotNull && obj.IsNull)
					{
						return true;
					}
					return false;
				}
				if (!obj.m_isFileOpen)
				{
					throw new InvalidOperationException(OracleStringResourceManager.GetErrorMesg(ResourceStringConstants.OBJECT_CLOSED));
				}
				if (obj.m_connection != m_connection)
				{
					throw new InvalidOperationException(OracleStringResourceManager.GetErrorMesg(ResourceStringConstants.CON_DIFFERENT_CONNECTIONS));
				}
				bool result = true;
				byte[] lobLocator = m_bfileImpl.m_lobLocator;
				byte[] lobLocator2 = obj.m_bfileImpl.m_lobLocator;
				if (lobLocator.Length != lobLocator2.Length)
				{
					result = false;
				}
				else
				{
					int num = lobLocator.Length;
					for (int i = 0; i < num; i++)
					{
						if (i == 10)
						{
							i++;
						}
						else if (lobLocator[i] != lobLocator2[i])
						{
							result = false;
							break;
						}
					}
				}
				return result;
			}
			catch (Exception ex)
			{
				OracleException.HandleError(OracleTraceLevel.Public, OracleTraceTag.Error, OracleTraceClassName.OracleBFile, OracleTraceFuncName.IsEqual, ex);
				throw;
			}
			finally
			{
				if (ProviderConfig.m_bTraceLevelPublic)
				{
					Trace.Write(OracleTraceLevel.Public, OracleTraceTag.Exit, OracleTraceClassName.OracleBFile, OracleTraceFuncName.IsEqual);
				}
			}
		}

		public void OpenFile()
		{
			if (ProviderConfig.m_bTraceLevelPublic)
			{
				Trace.Write(OracleTraceLevel.Public, OracleTraceTag.Entry, OracleTraceClassName.OracleBFile, OracleTraceFuncName.OpenFile);
			}
			try
			{
				if (!m_bNotNull)
				{
					throw new OracleNullValueException();
				}
				if (m_bClosed)
				{
					throw new InvalidOperationException(OracleStringResourceManager.GetErrorMesg(ResourceStringConstants.OBJECT_CLOSED));
				}
				if (!IsOpen)
				{
					SetDFNames();
					m_bfileImpl.OpenFile();
					m_isFileOpen = true;
				}
			}
			catch (Exception ex)
			{
				OracleException.HandleError(OracleTraceLevel.Public, OracleTraceTag.Error, OracleTraceClassName.OracleBFile, OracleTraceFuncName.OpenFile, ex);
				throw;
			}
			finally
			{
				if (ProviderConfig.m_bTraceLevelPublic)
				{
					Trace.Write(OracleTraceLevel.Public, OracleTraceTag.Exit, OracleTraceClassName.OracleBFile, OracleTraceFuncName.OpenFile);
				}
			}
		}

		public override int Read(byte[] buffer, int offset, int count)
		{
			if (ProviderConfig.m_bTraceLevelPublic)
			{
				Trace.Write(OracleTraceLevel.Public, OracleTraceTag.Entry, OracleTraceClassName.OracleBFile, OracleTraceFuncName.Read);
			}
			try
			{
				if (!m_bNotNull)
				{
					return 0;
				}
				if (m_bClosed || !m_isFileOpen)
				{
					throw new InvalidOperationException(OracleStringResourceManager.GetErrorMesg(ResourceStringConstants.OBJECT_CLOSED));
				}
				if (offset < 0)
				{
					throw new ArgumentOutOfRangeException("offset");
				}
				if (count < 0)
				{
					throw new ArgumentOutOfRangeException("count");
				}
				if (offset + count > buffer.Length)
				{
					throw new ArgumentOutOfRangeException("count");
				}
				if (count == 0)
				{
					return 0;
				}
				long num = 0L;
				num = ((m_position > 0) ? (m_position + 1) : 1);
				long num2 = 0L;
				num2 = ((count + offset > buffer.Length) ? (buffer.Length - offset) : count);
				long num3 = m_bfileImpl.Read(num, num2, offset, ref buffer);
				m_position += num3;
				return (int)num3;
			}
			catch (Exception ex)
			{
				OracleException.HandleError(OracleTraceLevel.Public, OracleTraceTag.Error, OracleTraceClassName.OracleBFile, OracleTraceFuncName.Read, ex);
				throw;
			}
			finally
			{
				if (ProviderConfig.m_bTraceLevelPublic)
				{
					Trace.Write(OracleTraceLevel.Public, OracleTraceTag.Exit, OracleTraceClassName.OracleBFile, OracleTraceFuncName.Read);
				}
			}
		}

		public override void Write(byte[] buffer, int offset, int count)
		{
			throw new NotSupportedException();
		}

		public void CloseFile()
		{
			if (ProviderConfig.m_bTraceLevelPublic)
			{
				Trace.Write(OracleTraceLevel.Public, OracleTraceTag.Entry, OracleTraceClassName.OracleBFile, OracleTraceFuncName.CloseFile);
			}
			try
			{
				if (!m_bNotNull)
				{
					throw new OracleNullValueException();
				}
				if (m_bClosed)
				{
					throw new InvalidOperationException(OracleStringResourceManager.GetErrorMesg(ResourceStringConstants.OBJECT_CLOSED));
				}
				if (m_isFileOpen)
				{
					m_bfileImpl.CloseFile();
					m_isFileOpen = false;
				}
			}
			catch (Exception ex)
			{
				OracleException.HandleError(OracleTraceLevel.Public, OracleTraceTag.Error, OracleTraceClassName.OracleBFile, OracleTraceFuncName.CloseFile, ex);
				throw;
			}
			finally
			{
				if (ProviderConfig.m_bTraceLevelPublic)
				{
					Trace.Write(OracleTraceLevel.Public, OracleTraceTag.Exit, OracleTraceClassName.OracleBFile, OracleTraceFuncName.CloseFile);
				}
			}
		}

		public int Compare(long src_offset, OracleBFile obj, long dst_offset, long amount)
		{
			if (ProviderConfig.m_bTraceLevelPublic)
			{
				Trace.Write(OracleTraceLevel.Public, OracleTraceTag.Entry, OracleTraceClassName.OracleBFile, OracleTraceFuncName.Compare);
			}
			try
			{
				if (m_bClosed)
				{
					throw new InvalidOperationException(OracleStringResourceManager.GetErrorMesg(ResourceStringConstants.OBJECT_CLOSED));
				}
				if (m_bNotNull && !m_isFileOpen)
				{
					throw new InvalidOperationException(OracleStringResourceManager.GetErrorMesg(ResourceStringConstants.OBJECT_CLOSED));
				}
				if (obj == null)
				{
					throw new ArgumentNullException("obj");
				}
				if (!m_bNotNull || obj.IsNull)
				{
					if (!m_bNotNull && obj.IsNull)
					{
						return 0;
					}
					throw new OracleNullValueException();
				}
				if (!obj.m_isFileOpen)
				{
					throw new InvalidOperationException(OracleStringResourceManager.GetErrorMesg(ResourceStringConstants.OBJECT_CLOSED));
				}
				if (obj.m_connection != m_connection)
				{
					throw new InvalidOperationException(OracleStringResourceManager.GetErrorMesg(ResourceStringConstants.CON_DIFFERENT_CONNECTIONS));
				}
				if (src_offset < 0)
				{
					throw new ArgumentOutOfRangeException("src_offset");
				}
				if (dst_offset < 0)
				{
					throw new ArgumentOutOfRangeException("dst_offset");
				}
				if (amount < 0)
				{
					throw new ArgumentOutOfRangeException("amount");
				}
				int num = 0;
				src_offset++;
				dst_offset++;
				if (m_command == null)
				{
					m_command = new OracleCommand();
				}
				m_command.Connection = m_connection;
				m_command.CommandText = "BEGIN :1 := DBMS_LOB.COMPARE(:LOB_1, :LOB_2, :AMOUNT, :OFFSET_1, :OFFSET_2); END;";
				m_command.CommandType = CommandType.Text;
				try
				{
					OracleParameter oracleParameter = new OracleParameter("return_value", OracleDbType.Int32, num, ParameterDirection.ReturnValue);
					oracleParameter.DbType = DbType.Int32;
					m_command.Parameters.Add(oracleParameter);
					m_command.Parameters.Add("provided_bfile", OracleDbType.BFile, obj, ParameterDirection.Input);
					m_command.Parameters.Add("current_bfile", OracleDbType.BFile, this, ParameterDirection.Input);
					m_command.Parameters.Add("compare_amount", OracleDbType.Int64, amount, ParameterDirection.Input);
					m_command.Parameters.Add("src_offset", OracleDbType.Int64, src_offset, ParameterDirection.Input);
					m_command.Parameters.Add("dst_offset", OracleDbType.Int64, dst_offset, ParameterDirection.Input);
					m_command.ExecuteNonQuery();
					num = (int)m_command.Parameters[0].Value;
				}
				finally
				{
					m_command.Parameters.Clear();
				}
				return num;
			}
			catch (Exception ex)
			{
				OracleException.HandleError(OracleTraceLevel.Public, OracleTraceTag.Error, OracleTraceClassName.OracleBFile, OracleTraceFuncName.Compare, ex);
				throw;
			}
			finally
			{
				if (ProviderConfig.m_bTraceLevelPublic)
				{
					Trace.Write(OracleTraceLevel.Public, OracleTraceTag.Exit, OracleTraceClassName.OracleBFile, OracleTraceFuncName.Compare);
				}
			}
		}

		public long CopyTo(OracleBlob obj)
		{
			if (ProviderConfig.m_bTraceLevelPublic)
			{
				Trace.Write(OracleTraceLevel.Public, OracleTraceTag.Entry, OracleTraceClassName.OracleBFile, OracleTraceFuncName.CopyTo);
			}
			try
			{
				if (!m_bNotNull)
				{
					throw new OracleNullValueException();
				}
				if (m_bClosed || !m_isFileOpen)
				{
					throw new InvalidOperationException(OracleStringResourceManager.GetErrorMesg(ResourceStringConstants.OBJECT_CLOSED));
				}
				if (obj == null)
				{
					throw new ArgumentNullException("obj");
				}
				return CopyTo(0L, obj, 0L, Length);
			}
			catch (Exception ex)
			{
				OracleException.HandleError(OracleTraceLevel.Public, OracleTraceTag.Error, OracleTraceClassName.OracleBFile, OracleTraceFuncName.CopyTo, ex);
				throw;
			}
			finally
			{
				if (ProviderConfig.m_bTraceLevelPublic)
				{
					Trace.Write(OracleTraceLevel.Public, OracleTraceTag.Exit, OracleTraceClassName.OracleBFile, OracleTraceFuncName.CopyTo);
				}
			}
		}

		public long CopyTo(OracleBlob obj, long dst_offset)
		{
			if (ProviderConfig.m_bTraceLevelPublic)
			{
				Trace.Write(OracleTraceLevel.Public, OracleTraceTag.Entry, OracleTraceClassName.OracleBFile, OracleTraceFuncName.CopyTo);
			}
			try
			{
				if (!m_bNotNull)
				{
					throw new OracleNullValueException();
				}
				if (m_bClosed || !m_isFileOpen)
				{
					throw new InvalidOperationException(OracleStringResourceManager.GetErrorMesg(ResourceStringConstants.OBJECT_CLOSED));
				}
				if (obj == null)
				{
					throw new ArgumentNullException("obj");
				}
				if (obj.IsNull)
				{
					throw new OracleNullValueException();
				}
				return CopyTo(0L, obj, dst_offset, Length);
			}
			catch (Exception ex)
			{
				OracleException.HandleError(OracleTraceLevel.Public, OracleTraceTag.Error, OracleTraceClassName.OracleBFile, OracleTraceFuncName.CopyTo, ex);
				throw;
			}
			finally
			{
				if (ProviderConfig.m_bTraceLevelPublic)
				{
					Trace.Write(OracleTraceLevel.Public, OracleTraceTag.Exit, OracleTraceClassName.OracleBFile, OracleTraceFuncName.CopyTo);
				}
			}
		}

		public long CopyTo(OracleClob obj)
		{
			if (ProviderConfig.m_bTraceLevelPublic)
			{
				Trace.Write(OracleTraceLevel.Public, OracleTraceTag.Entry, OracleTraceClassName.OracleBFile, OracleTraceFuncName.CopyTo);
			}
			try
			{
				if (!m_bNotNull)
				{
					throw new OracleNullValueException();
				}
				if (m_bClosed || !m_isFileOpen)
				{
					throw new InvalidOperationException(OracleStringResourceManager.GetErrorMesg(ResourceStringConstants.OBJECT_CLOSED));
				}
				if (obj == null)
				{
					throw new ArgumentNullException("obj");
				}
				if (obj.IsNull)
				{
					throw new OracleNullValueException();
				}
				return CopyTo(0L, obj, 0L, Length);
			}
			catch (Exception ex)
			{
				OracleException.HandleError(OracleTraceLevel.Public, OracleTraceTag.Error, OracleTraceClassName.OracleBFile, OracleTraceFuncName.CopyTo, ex);
				throw;
			}
			finally
			{
				if (ProviderConfig.m_bTraceLevelPublic)
				{
					Trace.Write(OracleTraceLevel.Public, OracleTraceTag.Exit, OracleTraceClassName.OracleBFile, OracleTraceFuncName.CopyTo);
				}
			}
		}

		public long CopyTo(OracleClob obj, long dst_offset)
		{
			if (ProviderConfig.m_bTraceLevelPublic)
			{
				Trace.Write(OracleTraceLevel.Public, OracleTraceTag.Entry, OracleTraceClassName.OracleBFile, OracleTraceFuncName.CopyTo);
			}
			try
			{
				if (!m_bNotNull)
				{
					throw new OracleNullValueException();
				}
				if (m_bClosed || !m_isFileOpen)
				{
					throw new InvalidOperationException(OracleStringResourceManager.GetErrorMesg(ResourceStringConstants.OBJECT_CLOSED));
				}
				if (obj == null)
				{
					throw new ArgumentNullException("obj");
				}
				if (obj.IsNull)
				{
					throw new OracleNullValueException();
				}
				return CopyTo(0L, obj, dst_offset, Length);
			}
			catch (Exception ex)
			{
				OracleException.HandleError(OracleTraceLevel.Public, OracleTraceTag.Error, OracleTraceClassName.OracleBFile, OracleTraceFuncName.CopyTo, ex);
				throw;
			}
			finally
			{
				if (ProviderConfig.m_bTraceLevelPublic)
				{
					Trace.Write(OracleTraceLevel.Public, OracleTraceTag.Exit, OracleTraceClassName.OracleBFile, OracleTraceFuncName.CopyTo);
				}
			}
		}

		public long CopyTo(long src_offset, OracleBlob obj, long dst_offset, long amount)
		{
			if (ProviderConfig.m_bTraceLevelPublic)
			{
				Trace.Write(OracleTraceLevel.Public, OracleTraceTag.Entry, OracleTraceClassName.OracleBFile, OracleTraceFuncName.CopyTo);
			}
			try
			{
				if (!m_bNotNull)
				{
					throw new OracleNullValueException();
				}
				if (m_bClosed || !m_isFileOpen)
				{
					throw new InvalidOperationException(OracleStringResourceManager.GetErrorMesg(ResourceStringConstants.OBJECT_CLOSED));
				}
				if (obj == null)
				{
					throw new ArgumentNullException("obj");
				}
				if (obj.IsNull)
				{
					throw new OracleNullValueException();
				}
				if (src_offset < 0)
				{
					throw new ArgumentOutOfRangeException("src_offset");
				}
				if (dst_offset < 0)
				{
					throw new ArgumentOutOfRangeException("dst_offset");
				}
				if (amount < 0)
				{
					throw new ArgumentOutOfRangeException("amount");
				}
				if (obj.m_connection != m_connection)
				{
					throw new InvalidOperationException(OracleStringResourceManager.GetErrorMesg(ResourceStringConstants.CON_DIFFERENT_CONNECTIONS));
				}
				if (obj.m_blobImpl.m_isTemporaryLob && !obj.m_blobImpl.m_doneTempLobCreate)
				{
					obj.CreateTempLob();
				}
				src_offset++;
				dst_offset++;
				return m_bfileImpl.CopyTo(obj.m_blobImpl.m_lobLocator, src_offset, dst_offset, amount);
			}
			catch (Exception ex)
			{
				OracleException.HandleError(OracleTraceLevel.Public, OracleTraceTag.Error, OracleTraceClassName.OracleBFile, OracleTraceFuncName.CopyTo, ex);
				throw;
			}
			finally
			{
				if (ProviderConfig.m_bTraceLevelPublic)
				{
					Trace.Write(OracleTraceLevel.Public, OracleTraceTag.Exit, OracleTraceClassName.OracleBFile, OracleTraceFuncName.CopyTo);
				}
			}
		}

		public long CopyTo(long src_offset, OracleClob obj, long dst_offset, long amount)
		{
			if (ProviderConfig.m_bTraceLevelPublic)
			{
				Trace.Write(OracleTraceLevel.Public, OracleTraceTag.Entry, OracleTraceClassName.OracleBFile, OracleTraceFuncName.CopyTo);
			}
			try
			{
				if (!m_bNotNull)
				{
					throw new OracleNullValueException();
				}
				if (m_bClosed || !m_isFileOpen)
				{
					throw new InvalidOperationException(OracleStringResourceManager.GetErrorMesg(ResourceStringConstants.OBJECT_CLOSED));
				}
				if (obj == null)
				{
					throw new ArgumentNullException("obj");
				}
				if (obj.IsNull)
				{
					throw new OracleNullValueException();
				}
				if (src_offset < 0)
				{
					throw new ArgumentOutOfRangeException("src_offset");
				}
				if (dst_offset < 0)
				{
					throw new ArgumentOutOfRangeException("dst_offset");
				}
				if (amount < 0)
				{
					throw new ArgumentOutOfRangeException("amount");
				}
				if (obj.m_connection != m_connection)
				{
					throw new InvalidOperationException(OracleStringResourceManager.GetErrorMesg(ResourceStringConstants.CON_DIFFERENT_CONNECTIONS));
				}
				if (obj.m_clobImpl.m_isTemporaryLob && !obj.m_clobImpl.m_doneTempLobCreate)
				{
					obj.CreateTempLob();
				}
				src_offset++;
				dst_offset++;
				return m_bfileImpl.CopyTo(obj.m_clobImpl.m_lobLocator, src_offset, dst_offset, amount);
			}
			catch (Exception ex)
			{
				OracleException.HandleError(OracleTraceLevel.Public, OracleTraceTag.Error, OracleTraceClassName.OracleBFile, OracleTraceFuncName.CopyTo, ex);
				throw;
			}
			finally
			{
				if (ProviderConfig.m_bTraceLevelPublic)
				{
					Trace.Write(OracleTraceLevel.Public, OracleTraceTag.Exit, OracleTraceClassName.OracleBFile, OracleTraceFuncName.CopyTo);
				}
			}
		}

		public object Clone()
		{
			if (ProviderConfig.m_bTraceLevelPublic)
			{
				Trace.Write(OracleTraceLevel.Public, OracleTraceTag.Entry, OracleTraceClassName.OracleBFile, OracleTraceFuncName.Clone);
			}
			try
			{
				if (!m_bNotNull)
				{
					return Null;
				}
				if (m_bClosed)
				{
					throw new InvalidOperationException(OracleStringResourceManager.GetErrorMesg(ResourceStringConstants.OBJECT_CLOSED));
				}
				byte[] array = null;
				if (m_bfileImpl.m_lobLocator != null)
				{
					array = new byte[m_bfileImpl.m_lobLocator.Length];
					Array.Copy(m_bfileImpl.m_lobLocator, array, array.Length);
				}
				return new OracleBFile(m_connection, array)
				{
					m_directoryName = m_directoryName,
					m_fileName = m_fileName,
					m_fileExists = m_fileExists,
					m_position = m_position,
					m_bNotNull = m_bNotNull
				};
			}
			catch (Exception ex)
			{
				OracleException.HandleError(OracleTraceLevel.Public, OracleTraceTag.Error, OracleTraceClassName.OracleBFile, OracleTraceFuncName.Clone, ex);
				throw;
			}
			finally
			{
				if (ProviderConfig.m_bTraceLevelPublic)
				{
					Trace.Write(OracleTraceLevel.Public, OracleTraceTag.Exit, OracleTraceClassName.OracleBFile, OracleTraceFuncName.Clone);
				}
			}
		}

		public override void Close()
		{
			if (ProviderConfig.m_bTraceLevelPublic)
			{
				Trace.Write(OracleTraceLevel.Public, OracleTraceTag.Entry, OracleTraceClassName.OracleBFile, OracleTraceFuncName.Close);
			}
			if (!m_bNotNull || m_bClosed)
			{
				return;
			}
			lock (lockBFile)
			{
				if (m_bClosed)
				{
					return;
				}
				try
				{
					if (m_connection != null && m_isFileOpen)
					{
						m_bfileImpl.CloseFile();
						m_isFileOpen = false;
					}
				}
				catch (Exception ex)
				{
					if (ProviderConfig.m_bTraceLevelPublic)
					{
						Trace.Write(OracleTraceLevel.Public, OracleTraceTag.Error, OracleTraceClassName.OracleBFile, OracleTraceFuncName.Close, ex.ToString());
					}
				}
				finally
				{
					m_bClosed = true;
					if (m_connection != null && m_connection.m_oracleConnectionImpl != null)
					{
						m_connection.m_oracleConnectionImpl.DeregisterForConnectionClose(this);
					}
					if (!m_bDisposed)
					{
						Dispose();
					}
					if (ProviderConfig.m_bTraceLevelPublic)
					{
						Trace.Write(OracleTraceLevel.Public, OracleTraceTag.Exit, OracleTraceClassName.OracleBFile, OracleTraceFuncName.Close);
					}
				}
			}
		}

		internal void ConnectionClose()
		{
			if (ProviderConfig.m_bTraceLevelPrivate)
			{
				Trace.Write(OracleTraceLevel.Private, OracleTraceTag.Entry, OracleTraceClassName.OracleBFile, OracleTraceFuncName.ConnectionClose);
			}
			try
			{
				if (!m_bClosed)
				{
					Close();
				}
			}
			catch (Exception ex)
			{
				OracleException.HandleError(OracleTraceLevel.Private, OracleTraceTag.Error, OracleTraceClassName.OracleBFile, OracleTraceFuncName.ConnectionClose, ex);
				throw;
			}
			finally
			{
				if (ProviderConfig.m_bTraceLevelPrivate)
				{
					Trace.Write(OracleTraceLevel.Private, OracleTraceTag.Exit, OracleTraceClassName.OracleBFile, OracleTraceFuncName.ConnectionClose);
				}
			}
		}

		public new void Dispose()
		{
			if (ProviderConfig.m_bTraceLevelPublic)
			{
				Trace.Write(OracleTraceLevel.Public, OracleTraceTag.Entry, OracleTraceClassName.OracleBFile, OracleTraceFuncName.Dispose);
			}
			try
			{
				Dispose(disposing: true);
			}
			catch (Exception ex)
			{
				if (ProviderConfig.m_bTraceLevelPublic)
				{
					Trace.Write(OracleTraceLevel.Public, OracleTraceTag.Error, OracleTraceClassName.OracleBFile, OracleTraceFuncName.Dispose, ex.ToString());
				}
			}
			finally
			{
				if (ProviderConfig.m_bTraceLevelPublic)
				{
					Trace.Write(OracleTraceLevel.Public, OracleTraceTag.Exit, OracleTraceClassName.OracleBFile, OracleTraceFuncName.Dispose);
				}
			}
		}

		protected override void Dispose(bool disposing)
		{
			if (ProviderConfig.m_bTraceLevelPrivate)
			{
				Trace.Write(OracleTraceLevel.Private, OracleTraceTag.Entry, OracleTraceClassName.OracleBFile, OracleTraceFuncName.Dispose);
			}
			if (m_bDisposed)
			{
				return;
			}
			lock (lockBFile)
			{
				if (m_bDisposed)
				{
					return;
				}
				try
				{
					if (!m_bNotNull)
					{
						return;
					}
					m_bDisposed = true;
					if (!m_bClosed)
					{
						Close();
					}
					if (disposing)
					{
						if (m_command != null)
						{
							m_command.Dispose();
							m_command = null;
						}
						m_connection = null;
					}
				}
				catch (Exception ex)
				{
					OracleException.HandleError(OracleTraceLevel.Private, OracleTraceTag.Error, OracleTraceClassName.OracleBFile, OracleTraceFuncName.Dispose, ex);
				}
				finally
				{
					GC.SuppressFinalize(this);
					if (ProviderConfig.m_bTraceLevelPrivate)
					{
						Trace.Write(OracleTraceLevel.Private, OracleTraceTag.Exit, OracleTraceClassName.OracleBFile, OracleTraceFuncName.Dispose);
					}
				}
			}
		}

		internal void GetDFNames()
		{
			if (ProviderConfig.m_bTraceLevelPrivate)
			{
				Trace.Write(OracleTraceLevel.Private, OracleTraceTag.Entry, OracleTraceClassName.OracleBFile, OracleTraceFuncName.GetDFNames);
			}
			try
			{
				bool flag = false;
				if (!m_isFileOpen)
				{
					m_bfileImpl.OpenFile();
					flag = true;
				}
				if (m_bfileImpl.m_lobLocator == null)
				{
					return;
				}
				if (m_command == null)
				{
					m_command = new OracleCommand();
				}
				m_command.Connection = m_connection;
				m_command.CommandText = "BEGIN DBMS_LOB.FILEGETNAME(:LOB_1, :DIR_ALIAS, :FILENAME); END;";
				m_command.CommandType = CommandType.Text;
				try
				{
					m_command.Parameters.Add("provided_bfile", OracleDbType.BFile, this, ParameterDirection.Input);
					m_command.Parameters.Add("dir_alias", OracleDbType.Varchar2, ParameterDirection.Output);
					m_command.Parameters[1].Size = 30;
					m_command.Parameters.Add("filename", OracleDbType.Varchar2, ParameterDirection.Output);
					m_command.Parameters[2].Size = 255;
					m_command.ExecuteNonQuery();
					m_directoryName = ((OracleString)m_command.Parameters[1].Value).Value;
					m_fileName = ((OracleString)m_command.Parameters[2].Value).Value;
				}
				finally
				{
					m_command.Parameters.Clear();
					if (flag)
					{
						m_bfileImpl.CloseFile();
					}
				}
			}
			catch (Exception ex)
			{
				OracleException.HandleError(OracleTraceLevel.Private, OracleTraceTag.Error, OracleTraceClassName.OracleBFile, OracleTraceFuncName.GetDFNames, ex);
				throw;
			}
			finally
			{
				if (ProviderConfig.m_bTraceLevelPrivate)
				{
					Trace.Write(OracleTraceLevel.Private, OracleTraceTag.Exit, OracleTraceClassName.OracleBFile, OracleTraceFuncName.GetDFNames);
				}
			}
		}

		internal void SetDFNames()
		{
			if (ProviderConfig.m_bTraceLevelPrivate)
			{
				Trace.Write(OracleTraceLevel.Private, OracleTraceTag.Entry, OracleTraceClassName.OracleBFile, OracleTraceFuncName.SetDFNames);
			}
			try
			{
				if (m_directoryName == null || m_fileName == null)
				{
					GetDFNames();
				}
				if (m_directoryName != null && m_directoryName.Length != 0 && m_fileName != null && m_fileName.Length != 0)
				{
					m_bfileImpl.SetDirFileName(m_directoryName, m_fileName);
					m_fileExists = true;
				}
			}
			catch (Exception ex)
			{
				OracleException.HandleError(OracleTraceLevel.Private, OracleTraceTag.Error, OracleTraceClassName.OracleBFile, OracleTraceFuncName.SetDFNames, ex);
				throw;
			}
			finally
			{
				if (ProviderConfig.m_bTraceLevelPrivate)
				{
					Trace.Write(OracleTraceLevel.Private, OracleTraceTag.Exit, OracleTraceClassName.OracleBFile, OracleTraceFuncName.SetDFNames);
				}
			}
		}
	}
}
